#include <Uefi.h>
#include <Library/UefiLib.h>

#include <Library/HiiLib.h>
#include <Library/UefiHiiServicesLib.h>
#include <Library/MemoryAllocationLib.h>

EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS Status;

  EFI_GUID Img_GUID = {0x87aafe54, 0x1a26, 0x4e60, {0x8b, 0x87, 0x1f, 0xf1, 0xe3, 0xf8, 0x3d, 0x16}};
  EFI_HII_HANDLE HiiHandle = NULL;

  EFI_HII_HANDLE *AllHandles = HiiGetHiiHandles(&Img_GUID);

  EFI_IMAGE_OUTPUT gSystemFrameBuffer;
  EFI_IMAGE_OUTPUT *pSystemFrameBuffer = &gSystemFrameBuffer;
  EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutputProtocol;

  Status = SystemTable->BootServices->LocateProtocol(&gEfiGraphicsOutputProtocolGuid, NULL, (VOID **)&GraphicsOutputProtocol);


  gSystemFrameBuffer.Width = (UINT16)GraphicsOutputProtocol->Mode->Info->HorizontalResolution;
  gSystemFrameBuffer.Height = (UINT16)GraphicsOutputProtocol->Mode->Info->VerticalResolution;
  gSystemFrameBuffer.Image.Screen = GraphicsOutputProtocol;

  if (AllHandles != NULL)
  {
    HiiHandle = AllHandles[0];
    FreePool(AllHandles);
  }
  else
  {
    HiiHandle = HiiAddPackages(&Img_GUID, NULL, HiiImageImages, NULL, NULL);
  }

  Status = gHiiImage->DrawImageId(
	  gHiiImage,
	  EFI_HII_DIRECT_TO_SCREEN,
	  HiiHandle,
	  IMAGE_TOKEN(IMG_24TB),
	  &pSystemFrameBuffer,
	  0,
	  0);

  Status = gHiiImage->DrawImageId(
	  gHiiImage,
	  EFI_HII_DIRECT_TO_SCREEN,
	  HiiHandle,
	  IMAGE_TOKEN(IMG_256B),
	  &pSystemFrameBuffer,
	  320,
	  500);

  return EFI_SUCCESS;
}